<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <style>
    .el-input__inner{
      border: 0;
      font-size: 1rem;
      text-align: center;
    }.el-input__prefix{
      display: none;
    }
    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <!-- <div class="x-header-g" id="header">
        <a class="x-header-arrow" @click="api.closeWin()"></a>
        <div class="x-header-t">训练考核</div>
      </div> -->
      <!--  -->
      <!-- <div class="x-trtali-box" id="calali"></div> -->
      <div class="x-ico-month x-ico-month2">
        <el-date-picker v-model="cardsmonth" type="month" placeholder="选择日" @change="getmonth" format="yyyy 年 MM 月" value-format="yyyyMM" :editable="notkey"></el-date-picker>
    </div>
      <!--  -->
      <div class="x-inui-bgbox">
        <template>
          <el-tabs v-model="activeName" @tab-click="handleClick" stretch="true">
            <el-tab-pane label="带训任务" name="first">
              <template>
                <el-table :data="tableDataone" style="margin-top:1rem;" border>
                  <el-table-column label="受训人" width="" fixed>
                    <template slot-scope="scope">
                      {{scope.row.username}}
                    </template>
                  </el-table-column>
                  <el-table-column label="学习岗位" width="">
                    <template slot-scope="scope">
                      {{scope.row.source_title}}
                    </template>
                  </el-table-column>
                  <el-table-column label="学习内容" width="">
                    <template slot-scope="scope">
                        {{scope.row.title}}
                    </template>
                  </el-table-column>
                  <el-table-column label="带训周期" width="">
                    <template slot-scope="scope">
                      {{scope.row.take_date1}}-{{scope.row.take_date2}}
                    </template>
                  </el-table-column>
                  <el-table-column label="完成带训确认" width="130">
                    <template slot-scope="scope">
                      
                      <el-button type="success" disabled  v-if="scope.row.is_take=='1'" size="mini">已完成</el-button>
                      <el-button type="danger" disabled  v-if="scope.row.is_take=='2'" size="mini">未完成</el-button>
                      <div v-if="scope.row.is_take=='0'">
                        <el-button type="primary" v-if="scope.row.is_finish!='0'" @click="okfinish(scope.row.id,scope.row.title)" size="mini">点击确认</el-button>
                      <el-button type="primary" v-else size="mini">未完成学习</el-button>
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column label="完成带训时间" width="">
                    <template slot-scope="scope">
                        {{scope.row.finish_taketime}}
                    </template>
                  </el-table-column>
                  <!-- <el-table-column label="自我评价" width="">
                    <template slot-scope="scope"> -->
                      <!-- 本人 -->
                      <!-- <div class="" v-if="scope.row.memberid==memid">
                        <el-button type="primary" v-if="scope.row.score=='0'" @click="getnumber(scope.row.id,scope.row.username,'1')" size="mini">点击评价</el-button>
                        <el-button type="text" disabled  v-else size="mini">{{scope.row.score}}分</el-button>
                      </div> -->
                      <!--  -->
                      <!-- <div v-else>
                        <div v-if="scope.row.score=='0'">未评价</div>
                        <el-button type="text" disabled  v-else size="mini">{{scope.row.score}}分</el-button>
                      </div>
                    </template>
                  </el-table-column> -->
                </el-table>
              </template>
            </el-tab-pane>
            <el-tab-pane label="考核任务" name="second">
              <template>
                <el-table :data="tableDatatwo" style="margin-top:1rem;">
                  <el-table-column label="受训人" width="" fixed>
                    <template slot-scope="scope">
                      {{scope.row.username}}
                    </template>
                  </el-table-column>
                  <el-table-column label="学习岗位" width="">
                    <template slot-scope="scope">
                      {{scope.row.source_title}}
                    </template>
                  </el-table-column>
                  <el-table-column label="学习内容" width="">
                    <template slot-scope="scope">
                        {{scope.row.title}}
                    </template>
                  </el-table-column>
                  <el-table-column label="完成带训确认" width="">
                    <template slot-scope="scope">
                      <div  v-if="scope.row.is_take=='0'" size="mini">未确认</div>
                      <div v-if="scope.row.is_take=='1'" size="mini">已完成</div>
                      <div v-if="scope.row.is_take=='2'" size="mini">未完成</div>
                    </template>
                  </el-table-column>
                  <!-- <el-table-column label="完成带训确认" width="">
                    <template slot-scope="scope">
                      <el-switch v-model="scope.row.switch" active-color="#058142" inactive-color="#ff4949"></el-switch>
                    </template>
                  </el-table-column> -->
                  <el-table-column label="完成带训时间" width="">
                    <template slot-scope="scope">
                      <!-- <el-date-picker v-model="scope.row.finish_time" type="date" placeholder="选择日期" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd"></el-date-picker> -->
                      {{scope.row.finish_taketime}}
                    </template>
                  </el-table-column>
                  <el-table-column label="完成考核确认" width="130">
                    <template slot-scope="scope">
                      <!-- <el-button type="primary" v-if="scope.row.is_exam=='0'" @click="examok(scope.row.id,scope.row.username)" size="mini">点击确认</el-button>
                      <el-button type="success" disabled  v-if="scope.row.is_exam=='1'" size="mini">已完成</el-button>
                      <el-button type="danger" disabled  v-if="scope.row.is_exam=='2'" size="mini">未完成</el-button> -->

                      <el-button type="success" disabled  v-if="scope.row.is_exam=='1'" size="mini">已完成</el-button>
                      <el-button type="danger" disabled  v-if="scope.row.is_exam=='2'" size="mini">未完成</el-button>
                      <div v-if="scope.row.is_exam=='0'">
                        <el-button type="primary" v-if="scope.row.is_take!='0'" @click="gettime(scope.row.id,scope.row.title)" size="mini">点击确认</el-button>
                      <el-button type="primary" v-else size="mini">未完成学习</el-button>
                    </template>
                  </el-table-column>
                  <!-- <el-table-column label="是否通过鉴定" width="">
                    <template slot-scope="scope">
                      <el-button type="primary" v-if="scope.row.is_appraisal==''" @click="appraisalok(scope.row.id,scope.row.username)" size="mini">点击确认</el-button>
                      <el-button type="success" disabled  v-if="scope.row.is_appraisal=='1'" size="mini">已完成</el-button>
                      <el-button type="danger" disabled  v-if="scope.row.is_appraisal=='2'" size="mini">未完成</el-button>
                    </template>
                  </el-table-column> -->
                  <el-table-column label="考核时间" width="">
                    <template slot-scope="scope">
                      {{scope.row.finish_examtime}}
                    </template>
                  </el-table-column>
                </el-table>
              </template>
            </el-tab-pane>
          </el-tabs>
        </template>
      </div>
      <!--  -->
      <el-dialog :title="'请对“'+scoretoasttitle + '”进行打分'" :visible.sync="dialogVisible" width="90%" center="true" close-on-click-modal="false" show-close="false">
        <div class="x-tra-nin">
          <el-input-number v-model="scoredata" @change="getscorenum" :min="1" :max="10" label="描述文字"></el-input-number>
          <div class="x-tra-desc"></div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="okgetscore">确 定</el-button>
        </span>
      </el-dialog>
      <!--  -->
      <el-dialog :title="timeshowname" :visible.sync="timetoast" width="90%" center="true" close-on-click-modal="false" show-close="false">
        <div class="">
         <el-select v-model="isfinish" placeholder="请选择">
            <el-option v-for="item in isfinishdata" :key="item.id" :label="item.title" :value="item.id"></el-option>
         </el-select>
          <el-date-picker v-model="finishtimedata" type="date" placeholder="选择日期" format="yyyy 年 MM 月 dd 日" value-format="timestamp" :editable="notkey"></el-date-picker>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="timetoast = false">取 消</el-button>
          <el-button type="primary" @click="okgettime">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
  <script type="text/javascript" src="../script/laydate/laydate.js"></script>
	<script>
apiready = function () {
    api.setRefreshHeaderInfo({
        loadingImg: 'widget://image/refresh.png',
        bgColor: '#ccc',
        textColor: '#fff',
        textDown: '下拉刷新...',
        textUp: '松开刷新...'
    }, function(ret, err) {
        setTimeout(function(){api.refreshHeaderLoadDone()},500)
        vm.getdataone()
        vm.getdatatwo()
    });
    var ttype = api.pageParam.type;
    var tgetmonth = api.pageParam.timemonth;



    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          activeName: 'first',
          tableDataone:[],
          tableDatatwo:[],
          thtype:'',
          thmonth:'',
          dialogVisible:false,
          scoretoasttitle:'',
          scoredata:5,
          scoretoastid:'',
          timetoast:false,
          timeshowname:'',
          finishtimedata:'',
          timeshowid:'',
          notkey:false,
          memid:'',
          cardsmonth:'',
          isfinishdata:[
              {
                  title:'已完成',
                  id:'1'
              },
              {
                  title:'未完成',
                  id:'2'
              }
          ],
          isfinish:'',

        }
      },
      created:function() {
        var that=this;
        //当前月份
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth()+1;
        if(month<10){
          month = '' + 0 + month;
        }
        var toMonth = '' + year + month;
        that.cardsmonth = toMonth;


      },
      mounted:function(){
        var that=this;
        // that.thmonth = tgetmonth;
        // laydate.render({
        //   elem: '#calali',
        //   position: 'static',
        //   btns:['now'],
        //   format:'yyyy-MM-dd',
        //   value:that.thmonth,
        //   // theme:'#058142',
        //   change:function(value,date){
        //     console.log(value);
        //     that.thmonth = value;
        //     that.getdataone()
        //   }
        // });
        that.memid = $api.getStorage('myid');
        that.getdataone()

      },
      methods: {
        getmonth:function(){
          this.gettrainadmin()
        },
        //完成考核确认
        examok:function(id,name){
          var that = this;
          api.actionSheet({
              title: '请确认“'+ name + '”是否完成考核',
              cancelTitle: '取消',
              buttons: ['已完成', '未完成']
          }, function(ret, err) {
              var index = ret.buttonIndex;
              console.log(index);// 1 2
              if(index=='1'){
                that.examgoajax(id,index,'setExam')
              }else if(index=='2'){
                that.examgoajax(id,index,'setExam')
              }

          });

        },
        //完成考核 提交
        examgoajax:function(id,index,url){
          let that=this;
          api.ajax({
            url:baseurl+'api/task/' + url,
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                id:id,
                type:index
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.getdataone()


              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //完成鉴定确认
        appraisalok:function(id,name){
          var that = this;
          api.actionSheet({
              title: '请确认“'+ name + '”是否完成鉴定',
              cancelTitle: '取消',
              buttons: ['已完成', '未完成']
          }, function(ret, err) {
              var index = ret.buttonIndex;
              console.log(index);// 1 2
              if(index=='1'){
                that.examgoajax(id,index,'setAppraisal')
              }else if(index=='2'){
                that.examgoajax(id,index,'setAppraisal')
              }

          });

        },
        //完成带训时间
        gettime:function(id,name){
          var that = this;
          that.isfinish = '';
          that.finishtimedata = '';
          that.timetoast = true;
          that.timeshowname = name;
          that.timeshowid = id;
        },
        //完成带训时间 提交
        okgettime:function(){
          let that=this;
          that.timetoast = false;
          api.ajax({
            url:baseurl+'api/task/setFinish',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                id:that.timeshowid,
                type:that.isfinish,
                finish_time:that.finishtimedata/1000
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.getdataone()
                that.getdatatwo()


              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //查看学习内容
        seestudypro:function(name,con){
          var that = this;
          api.alert({
              title: '“' + name + '”的学习内容:',
              msg: con,
          }, function(ret, err) {

          });
        },
        //获取打分分数
        getscorenum:function(val){
          console.log(val);
          var that = this;
          that.scoredata = val;
        },
        //自我评价
        getnumber:function(id,name){
          var that = this;
          that.dialogVisible = true;//显示弹窗
          that.scoretoasttitle = name;
          that.scoretoastid = id;

        },
        //自我评价提交
        okgetscore:function(){
          let that=this;
          that.dialogVisible = false;//显示弹窗
          api.ajax({
            url:baseurl+'api/task/setTakeScore',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                id:that.scoretoastid,
                score:that.scoredata
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.getdataone()


              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //带训确认
        okfinish:function(id,title){
            this.timetoast = true;
            this.timeshowid = id;
            this.timeshowname = title;
        //   console.log(id);
        //   var that = this;
        //   api.actionSheet({
        //       title: '请确认“'+ name + '”是否完成带训',
        //       cancelTitle: '取消',
        //       buttons: ['已完成', '未完成']
        //   }, function(ret, err) {
        //       var index = ret.buttonIndex;
        //       console.log(index);// 1 2
        //       if(index=='1'){
        //         that.settake(id,index)
        //       }else if(index=='2'){
        //         that.settake(id,index)
        //       }

        //   });
        },
        //带训是否完成 提交
        settake:function(id,index){
          let that=this;
          api.ajax({
            url:baseurl+'api/task/setTake',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                id:id,
                type:index
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.getdataone()
                that.getdatatwo()


              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        getdataone:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/task/take',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                date:that.cardsmonth
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.tableDataone = ret.data.list;

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        getdatatwo:function(){
            let that=this;
          api.ajax({
            url:baseurl+'api/task/exam',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                date:that.cardsmonth
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.tableDatatwo = ret.data.list;

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //选项卡
        handleClick:function(tab,event){
          var that = this;
          let id = event.target.getAttribute('id').split('-');
          let whitetab = id.join('').substring(3,9);
          if(whitetab=='second'){
            that.getdatatwo()
          }

        },
      }
    })
	}


	</script>
</body>
</html>
